<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/MF93FL27/modconf.mex");
MYTCONN();

	$GET = $GLOBALS['MYT']->db_array("SELECT IF(cnm_Group=0,cnm_Name,cnm_Name) AS O_ID, COUNT(CliExtID) AS COL1, OriCiudad AS COL2, SUM(FraEnviado) AS ValorPeriodo, SUM(FraEnviado) AS ValorTotal
						 FROM systemoffice.comr_conhecimento
							INNER JOIN clientes_ext ON cnm_ID = CliConhecimento
							INNER JOIN clientes ON CliNumero = CliExtNumero
							LEFT OUTER JOIN origenes ON OriNumero = cnm_Group
                                                        LEFT JOIN facturas ON FraCliNumero = CliNumero
						 	WHERE DATE(CliFechaAlta) BETWEEN '{$_POST['TimeStart']}' AND '{$_POST['TimeEnd']}'
						GROUP BY cnm_Name, cnm_Group ORDER BY cnm_Name ASC");
	$CARD = $GET[0];
?>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("BoardPanel"));

Ext.onReady(function(){
  windowHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
	windowHeight = window.innerHeight-$elem;
  } else if( document.documentElement && (document.documentElement.clientHeight ) ) {
	windowHeight = document.documentElement.clientHeight-200;
  } 
    var myData = [
	<?php   
	for ($i=1;$i<=$CARD;$i++) { 
	echo '['.$i.',\''.$GET[$i]['O_ID'].'\',\''.$GET[$i]['COL1'].'\',\''.$GET[$i]['COL2'].'\',\''.number_format($GET[$i]['ValorPeriodo'],2,'.',',').'\',\''.number_format($GET[$i]['ValorTotal'],2,'.',',').'\']';
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
	       {name: 'O_ID', type: 'string'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
               {name: 'COL4', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Tipo", width: 300, sortable: true, locked:true, dataIndex: 'O_ID'},
        {header: "Loja", width: 120, sortable: true, locked:true,dataIndex: 'COL2'},
        {header: "Quantidade", width: 120, align: "right", sortable: true, locked:true,dataIndex: 'COL1'},
        {header: "Enviado no Perido", width: 120, align: "right", sortable: true, locked:true,dataIndex: 'COL3'},
        {header: "Enviado Total", width: 120, align: "right", sortable: true, locked:true,dataIndex: 'COL4'}
    ]);

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({

        layout: 'fit',
	ds: ds,
	cm: colModel,
	sm: selmode,
	height: windowHeight,
        renderTo: 'BoardPanel'
    });
		
});
</script>